﻿#include "testthread.h"
#include <QDebug>
#include "serial/mserialportlist.h"
#include "debug/log_manager.h"

TestThread::TestThread() : QThread(nullptr)
{
    moveToThread(this);
}

TestThread::~TestThread()
{
    quit();
    wait();
}

void TestThread::run(void)
{
    MSerialPortList *serial_lists = MSerialPortList::instance();
//    qRegisterMetaType<QSerialPortInfoList>("QSerialPortInfoList");
//    qRegisterMetaType<QSerialPortInfoList>("QSerialPortInfoList&");
//    connect(serial_lists, &MSerialPortList::new_serial_port_update,
//            this, [=](const QSerialPortInfoList &lists){
//        qDebug() << "TestThread : serial port update" << QThread::currentThread();
//        foreach(QSerialPortInfo serial, lists) {
//            qDebug() << serial.portName() << ":" <<
//                        serial.description() << ":" << serial.manufacturer();
//        }
//    });
    qDebug() << "TestThread : serial port update" << QThread::currentThread();
    QSerialPortInfo info = serial_lists->get_select_serial();
    qDebug() << info.portName() << QThread::currentThread();
//    //exec();
    log_msg_send_to_ui("TestThread : serial port update");
    sleep(10);
}
